//package com.cw.WebSocketController;
//
//import cn.hutool.core.date.DateTime;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.cw.common.R;
//import com.cw.entity.MailInfo;
//import com.cw.entity.Runner;
//import com.cw.filter.LoginCheckFilter;
//import com.cw.service.RunnerService;
//import com.cw.utils.CodeUtils;
//import com.cw.utils.MailUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.concurrent.TimeUnit;
//
///**
// * @author Nice_BernardShaw
// * @date 2022/10/31 22:30
// */
//@RestController
//@RequestMapping("/runner")
//@Slf4j
//
//public class RunnerController {
//    @Resource
//    private RunnerService runnerService;
//    @Resource
//    private RedisTemplate redisTemplate;
//    @CrossOrigin
//    @PostMapping("/sendMsg")
//    public R sendMsg(@RequestBody Runner runner) {
//        log.info("获取到的手机号为：{}",runner);
//        //获取手机号
//        MailInfo mailInfo = new MailInfo();
//        if (runner.getEmail()!=null){
////            String code = ValidateCodeUtils.generateValidateCode(6).toString();
//            String generateCode = CodeUtils.GenerateCode();
//            String str = "<!DOCTYPE html><html><head><meta charset='UTF-8'></head><body><p style='font-size: 20px;font-weight:bold;'>尊敬的：【"+runner.getEmail()+"】用户，您好！</p>"
//                    + "<p style='text-indent:2em; font-size: 20px;'>您本次的验证码是 "
//                    + "<span style='font-size:30px;font-weight:bold;color:red'>" +generateCode  + "</span>，1分钟之内有效，请尽快使用！</p>"
//                    + "<p style='text-align:right; padding-right: 20px;'"
//                    + "<a href='http://127.0.0.1:8080/front/page/login.html' style='font-size: 18px'点击链接跳转回登录界面</a></p>"
//                    + "<span style='font-size: 18px; float:right; margin-right: 60px;'>" + DateTime.now() + "</span></body></html>";
//            mailInfo.setMessage(str);
//            ArrayList<String> toMails = new ArrayList<>();
//            toMails.add(runner.getEmail());
//            mailInfo.setMails(toMails);
//            MailUtils.sendMail2QQ(mailInfo);
//            redisTemplate.opsForValue().set("runner_code:"+runner.getEmail(), generateCode,5, TimeUnit.MINUTES);
//            log.info("{}",generateCode);
//            return R.success("验证码发送成功！");
//        }
//        return R.error("验证码发送失败");
//
//    }
//    @CrossOrigin
//    @PostMapping("/saveRunner")
//    public  R registry (@RequestBody Runner runner){
//        //获取登录信息
//        log.info("获取到的数据是：{}",runner);
//        String code = runner.getCode();
//        String sessionCode = (String) redisTemplate.opsForValue().get("runner_code:"+runner.getEmail());
//        //比较验证码是否相同
//        if ( !code.equals(sessionCode)){
//            return R.error("输入的验证码错误");
//        }
//        //核对账号是否在数据库中
//        LambdaQueryWrapper<Runner> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(Runner::getRunnerId,runner.getRunnerId());
//        Runner one = runnerService.getOne(wrapper);
//        if (one==null){
//             runnerService.save(runner);
//            //删除验证码
//            redisTemplate.delete("runner_code:"+runner.getEmail());
//            return R.success(runner);
//        }
//        return R.error("注册失败");
//    }
//    @CrossOrigin
//    @PostMapping("/getRunnerByRunnerId")
//    public R getRunnerByRunnerId(@RequestBody Runner runner){
//        Runner one = this.runnerService.getOne(new LambdaQueryWrapper<Runner>().eq(runner.getRunnerId() != null, Runner::getRunnerId, runner.getRunnerId()));
//        if (one!=null){
//            return R.success("身份证已被注册");
//        }
//        return R.success(null);
//    }
//    @CrossOrigin
//    @PostMapping("/login")
//    public R login(@RequestBody Runner runner){
//        Runner one = this.runnerService.getOne(new LambdaQueryWrapper<Runner>()
//                .eq(runner.getRunnerPhone() != null, Runner::getRunnerPhone, runner.getRunnerPhone())
//                .eq(runner.getPassword() != null, Runner::getPassword, runner.getPassword()));
//        if (one!=null){
//            this.redisTemplate.opsForValue().set("RUNNER:"+one.getRunnerId(),one);
////            LoginCheckFilter.id= Long.valueOf(one.getRunnerId());
//            return R.success(one);
//        }
//        return  R.error("无此用户！");
//    }
//}
